/**
 * 495. 提莫攻击
 */
class Solution2 {
    public int findPoisonedDuration(int[] timeSeries, int duration) {
        int ret = 0, n = timeSeries.length;
        for(int i = 0; i < n; i++) {
            if((i == (n - 1)) || (timeSeries[i + 1] - timeSeries[i] >= duration)) {
                ret += duration;
            } else {
                ret += timeSeries[i + 1] - timeSeries[i];
            }
        }
        return ret;
    }
}